<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('角色信息列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>角色名称：</label>
                                <input type="text" name="roleName"/>
                            </li>
                            <li>
                                <label>权限字符：</label>
                                <input type="text" name="roleKey"/>
                            </li>

                            <li>
                                角色状态：<select name="status" th:with="type=${@dict.getType('sys_normal_disable')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                        </select>
                            </li>

                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="sxt:juese:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="sxt:juese:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="sxt:juese:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="sxt:juese:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var datas = [[${@dict.getType('sys_normal_disable')}]];
        var editFlag = [[${@permission.hasPermi('sxt:juese:edit')}]];
        var removeFlag = [[${@permission.hasPermi('sxt:juese:remove')}]];
        var prefix = ctx + "sxt/juese";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "角色信息",
                columns: [{
                    checkbox: true
                },
                    {
                        field: 'roleId',
                        title: '角色编号'
                    },
                    {
                        field: 'roleName',
                        title: '角色名称',
                        sortable: true
                    },
                    {
                        field: 'roleKey',
                        title: '权限字符',
                        sortable: true
                    },
                    {
                        field: 'dataScope',
                        title: '数据权限',
                        formatter: function(value, item, index) {
                            if (item.dataScope == '1') {
                                return '<span class="badge badge-primary">全部数据权限</span>';
                            }
                            else if (item.dataScope == '2') {
                                return '<span class="badge badge-success">自定义数据权限</span>';
                            }
                            else if (item.dataScope == '3') {
                                return '<span class="badge badge-info">本部门数据权限</span>';
                            }
                            else if (item.dataScope == '4') {
                                return '<span class="badge badge-warning">本部门及以下数据权限</span>';
                            }
                            else if (item.dataScope == '5') {
                                return '<span class="badge badge-danger">仅本人数据权限</span>';
                            }
                        }
                    },
                    {
                        field: 'roleSort',
                        title: '显示顺序',
                        sortable: true
                    },
                    {
                        field: 'status',
                        title: '角色状态',
                        align: 'center',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(datas, value);
                        }
                    },
                    {
                        field: 'createTime',
                        title: '创建时间',
                        sortable: true
                    },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        // var actions = [];
                        // actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.roleId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        // actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.roleId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        // return actions.join('');
                        if (row.roleId != 1) {
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.roleId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.roleId + '\')"><i class="fa fa-remove"></i>删除</a> ');
                            var more = [];
                            more.push("<a class='btn btn-default btn-xs " + editFlag + "' href='javascript:void(0)' onclick='authDataScope(" + row.roleId + ")'><i class='fa fa-check-square-o'></i>数据权限</a> ");
                            more.push("<a class='btn btn-default btn-xs " + editFlag + "' href='javascript:void(0)' onclick='authUser(" + row.roleId + ")'><i class='fa fa-user'></i>分配用户</a>");
                            actions.push('<a tabindex="0" class="btn btn-info btn-xs" role="button" data-container="body" data-placement="left" data-toggle="popover" data-html="true" data-trigger="hover" data-content="' + more.join('') + '"><i class="fa fa-chevron-circle-right"></i>更多操作</a>');
                            return actions.join('');
                        } else {
                            return "";
                        }
                    }
                }]
            };
            $.table.init(options);
        });

        /* 角色管理-分配用户 */
        function authUser(roleId) {
            var url = prefix + '/authUser/' + roleId;
            $.modal.openTab("分配用户", url);
        }
    </script>
</body>
</html>